﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NLite;
using NHibernate;
using NHibernate.Linq;
using NLite.Persistence;

namespace NLite.NHPersistence
{
    public class NHRepository<T,TId>:IRepository<T,TId>
    {
        protected INhibernateSession Provider;
        public NHRepository(INhibernateSession provider)
        {
            Provider = provider;
        }

        public void SaveOrUpdate(T entity)
        {
            var session = Provider.CurrentSession;
            session.SaveOrUpdate(entity);
            session.Flush();
        }

        public virtual void Delete(params TId[] ids)
        {
            var session = Provider.CurrentSession;
            foreach (var id in ids)
            {
                var entity = session.Load<T>(id);
                session.Delete(entity);
            }
            session.Flush();
        }
      
    }
}
